import { fileURLToPath, URL } from 'node:url';

import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import legacy from '@vitejs/plugin-legacy'; //(1)处理代码兼容
// terser 是一个 JavaScript (2)压缩工具

// element plus 按需加载 和导入elemeng icon
import AutoImport from 'unplugin-auto-import/vite'; //插件自动导入配置
import Components from 'unplugin-vue-components/vite'; //Vue 的按需组件自动导入  例：@/components下的组件自动导入 不需import
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';

// 简化css w-5 等的解析
import UnoCSS from 'unocss/vite';
// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  plugins: [
    vue(),
    UnoCSS(),
    legacy(),
    AutoImport({
      resolvers: [
        //element plus 按需加载 自动导入 Element Plus 相关函数，如：ElMessage, ElMessageBox... (带样式)
        ElementPlusResolver()
      ]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    host: '0.0.0.0'
  },
  css: {
    preprocessorOptions: {
      scss: {
        // additionalData: `@import "@/assets/styles/mixin.scss";`
        api: 'modern-compiler',
        silenceDeprecations: ['legacy-js-api']
      }
    }
  }
});
